package ch.unifr.dokpe.htmlpicker.urlformater;

public class IsiRefUrlFormater extends AbstractUrlFormater {

/**
* Replace a string limited by &amp;isickref and the next &amp; or the end of the string if not found
* @see ch.unifr.dokpe.htmlpicker.urlformater.DefaultUrlFormater#formatUrl(String url, String param, int searchNo)
*/

public String formatUrl(String url, String param, int searchNo){
	//System.out.println("IsiRefUrlFormatter.url: " + url);
	//System.out.println("IsiRefUrlFormatter.param: " + param);
	String target ="&isickref=" ;
	int pos = param.indexOf(target);
	if (pos==-1) {
		//target = "&rec_id=";
		target = "&recid=";
		pos = param.indexOf(target);	
	}
	if (pos==-1){
		throw new RuntimeException ("IsiRefUrlFormatter: can't find reccord's ref in " + url);	
	} else {
		pos +=target.length();
	}
	int poslast = param.indexOf("&", pos+1);
	if (poslast ==-1){
		poslast= param.length();
	}
	String ref = param.substring(pos,poslast);
	//System.out.println("getFullURL: " + ref);
	//System.out.println ("getFullURL: " + baseURL.replace("&isickref=&", "&isickref=" + ref + "&"));
	return url.replaceFirst(param_symb,ref); 
    }
 }//class
